import BirdControl from "./BirdControl";

const { ccclass, property } = cc._decorator;

@ccclass
export default class bgControl extends cc.Component {

	// 速度
	@property
	speed: number = 4
	// 宽度
	@property
	width: number = 288
	// 小鸟
	@property(BirdControl)
	bird: BirdControl = null

	// onLoad () {}

	start() {
		// 点击监听
		for (let bg of this.node.children) {
			bg.on(cc.Node.EventType.MOUSE_DOWN, () => {
				this.bird.fly()
			})
		}
	}

	update(dt) {
		// 移动
		for (let bg of this.node.children) {
			bg.x -= this.speed * dt
			if (bg.x < -this.width) {
				bg.x += this.width * 2
			}
		}
	}
}
